import dayjs from 'dayjs';

dayjs.locale('zh-cn'); // 设置语言

const useDateFormatter = (defaultFormatString = 'YYYY-MM-DD HH:mm:ss') => {
  const formatDate = (date?: Date | string | number, formatString?: string): string => {
    if (!date)
      return '';
    return dayjs(date).format(formatString || defaultFormatString);
  };

  return { formatDate };
};

export default useDateFormatter;
